# Maintainer: David Sugar <tychosoft@gmail.com>
# Contributor: David Sugar <tychosoft@gmail.com>
pkgname=coventry
pkgver=0.8.1
pkgrel=0
pkgdesc="Residential IP telephony gateway"
url="https://www.tychosoft.com/tychosoft/coventry/wiki"
arch="all"
license="GPL-3.0-or-later"
makedepends="cmake fmt-dev>=8.1.0 openssl-dev moderncli-dev>=0.8.0 libosip2-dev>=5.3.0 libexosip2-dev>=5.3.0"
subpackages="$pkgname-doc $pkgname-openrc"
source="https://www.tychosoft.com/api/packages/tychosoft/generic/coventry/$pkgver/coventry-$pkgver.tar.gz coventry.initd"

build() {
	cmake \
		-DCMAKE_INSTALL_SYSCONFDIR:PATH=/etc \
		-DCMAKE_INSTALL_LOCALSTATEDIR:PATH=/var \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=/usr/lib \
		-DSERVER_PREFIX_PATH=/var/lib/coventry \
		-DSERVER_LOGGER_PATH=/var/log/coventry \
		-DSERVER_CONFIG_FILE=/etc/coventry.conf \
		-DCMAKE_BUILD_TYPE=Release .
	make
}

check() {
	make test
}

package() {
	DESTDIR="$pkgdir" make install
	strip "$pkgdir"/usr/bin/pbx-*
	strip "$pkgdir"/usr/sbin/coventry
	gzip "$pkgdir"/usr/share/man/man*/*
	install -d -m 750 -g adm "$pkgdir"/var/log/$pkgname
	install -d -m 700 "$pkgdir"/var/lib/$pkgname
	install -D -m 700 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 LICENSE.md "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.md
	install -Dm644 README.md "$pkgdir"/usr/share/doc/$pkgname/README.md
	install -Dm644 FEATURES.md "$pkgdir"/usr/share/doc/$pkgname/FEATURES.md
	install -Dm644 AGENTS.md "$pkgdir"/usr/share/doc/$pkgname/AGENTS.md
	install -Dm644 UTILITIES.md "$pkgdir"/usr/share/doc/$pkgname/UTILITIES.md
}

sha512sums="
dfaef6e24d47f0c27a3b2833da3835b479a3e8c1226bb24e48752fcd610e52baf5a30853467bb1ed4dcd170731e8df81b9df6e65d597e5b693b61bdfde1bb664  coventry-0.8.1.tar.gz
fd601c29764a34d3f8f1102982885a350a7a7f16edcbb8fdb1096b77600c686a87ec2de37ee502c9a7f1494e9b1dd7f8050eb6fe069f2e57ebc0e8da958f9bd3  coventry.initd
"
